textlayout: Clip selection bounds to the line extents
authorAlexander Mikhaylenko <alexm@gnome.org>
Mon, 3 May 2021 19:32:25 +0000 (00:32 +0500)
committerAlexander Mikhaylenko <alexm@gnome.org>
Mon, 3 May 2021 20:08:19 +0000 (01:08 +0500)
The rest of the line will be painted separately.

gtk/gtktextlayout.c

index 2037eab42640647a12e62078a08211b315c0c470..7d6770e252f62d583d6e1ad53c0f755c2b1df017 100644 (file)
@@ -3951,6 +3951,17 @@ render_para (GskPangoRenderer   *crenderer,
                   bounds.size.width = PANGO_PIXELS (ranges[2*i + 1]) - PANGO_PIXELS (ranges[2*i]);
                   bounds.size.height = selection_height;
 
+                  if (bounds.origin.x < PANGO_PIXELS (line_rect.x))
+                    {
+                      bounds.size.width -= PANGO_PIXELS (line_rect.x) - bounds.origin.x;
+                      bounds.origin.x = PANGO_PIXELS (line_rect.x);
+                    }
+
+                  bounds.size.width = MIN (bounds.size.width,
+                                           PANGO_PIXELS (line_rect.x) +
+                                           PANGO_PIXELS (line_rect.width) -
+                                           bounds.origin.x);
+
                   gtk_snapshot_append_color (crenderer->snapshot, selection, &bounds);
 
                   if (draw_selection_text)